package reviewAlgorithms.greedyThought;

import java.util.Arrays;
import java.util.Comparator;

public class IndMinArrowShots {
    public static void main(String[] args) {
        int[][] points = {{10,16},{2,8},{1,6},{7,12}};
        System.out.println(findMinArrowShots(points));
    }

    public static int findMinArrowShots(int[][] points) {
        if (points == null || points.length < 1){
            return 0;
        }
        Arrays.sort(points, Comparator.comparingInt(o1 -> o1[0]));
        int i = 0;
        int count = 0;
        while (i < points.length){
            int end = points[i][1];
            int j = i + 1;
            while (j < points.length && points[j][0] <= end){
                if (end > points[j][1]){
                    end = points[j][1];
                }
                j ++;
            }
            count ++;
            i = j;
        }
        return count;
    }
}
